Skip to content

agentHost: turn on client forwarding with a CLI flag and from editor windows - #350856

Open
Christof Marti (chrmarti) wants to merge 2 commits into
mainfrom
chrmarti/client-forwarding-flag
Open

Christof Marti (chrmarti) wants to merge 2 commits into
mainfrom
chrmarti/client-forwarding-flag

Conversation

@chrmarti

@chrmarti Christof Marti (chrmarti) commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #350751. Replaces the environment variable that the Dev Container launcher used to turn on client forwarding with a code agent host --client-forwarding flag, and lets editor windows connected to a Dev Container turn it on for the Agent Host their server starts, which the launcher may reuse.

The launcher prefixed its spawn command with VSCODE_AGENT_HOST_CLIENT_FORWARDING=1, which was implicit. And since the launcher reuses any running Agent Host of the same quality, it often picked the one a remote editor window's server had started in the container, which never forwarded.

CLI (cli/)

  • Hidden --client-forwarding flag on code agent host / code agent, not allowed with --tunnel or --github-environment.
  • The supervisor sets VSCODE_AGENT_HOST_CLIENT_FORWARDING=1 for the server it starts only with the flag, and removes it otherwise, so an inherited variable can't turn forwarding on. The server passes it on to its Agent Host, which reads and removes it as before.

Editor windows

  • An editor window connected to a Dev Container (dev-container or attached-container) asks its server for forwarding with a new clientForwarding IPC connection option, next to the resolver environment it already passes.
  • The server then starts its Agent Host with the variable. It keeps doing so for crash restarts once a window asked, since the Agents window's Dev Container connections may still use that Agent Host.
  • The variable's constant moves to common/agentService.ts as AgentHostClientForwardingEnvVar, so the server can use it.

Dev Container launcher

  • Reuses the running Agent Host as before, regardless of how it was started.
  • Starts a new one with --client-forwarding instead of the variable. The CLI of the client's commit and the latest CLI that dev builds use get the flag, as do fallback CLIs whose --version is 1.149 or later (or dev); the CLI installer now also returns a fallback CLI's --version output. An older fallback CLI starts the Agent Host without the flag, with a warning.
  • Stops waiting for the new Agent Host to register as soon as its start command exits with an error, instead of after the 5-minute registration timeout, and reports the command's error output.
  • When the CLI rejects the flag (unexpected argument '--client-forwarding'), as 1.149 builds from before it do, starts the Agent Host again without it.

How to test

  1. In the Agents window, start a Dev Container session for a folder whose container isn't running. In the container, ps -ef | grep agent shows agent host ... --client-forwarding, and Git credentials, ssh-add -l and GPG signing work in a session's terminal.
  2. Open the same folder in a Dev Container editor window first, use chat there to start the server's Agent Host, then connect from the Agents window: it reuses that Agent Host, and forwarding works.

Validation:

  • pnpm run typecheck-client: passed
  • node build/oxlint.ts <changed .ts files>: passed
  • pnpm run precommit (hygiene on the staged files): passed
  • pnpm run build-fast --client-only: passed
  • .\scripts\test.bat --run src/vs/platform/agentHost/test/node/devContainerAgentHostService.test.ts --run src/vs/platform/agentHost/test/node/sshRemoteAgentHostHelpers.test.ts --run src/vs/platform/agentHost/test/node/remoteAgentHostCliInstaller.test.ts --run src/vs/platform/agentHost/test/node/sshRemoteAgentHostService.test.ts --run src/vs/platform/agentHost/test/node/agentHostClientForwarding.test.ts --run src/vs/platform/agentHost/test/node/agentHostEndpointRegistry.test.ts --run src/vs/server/test/node/agentHostChannel.test.ts --run src/vs/server/test/node/serverAgentHostEnvironment.test.ts --run src/vs/workbench/services/agentHost/test/browser/editorRemoteAgentHostServiceClient.test.ts: passed (386 passing, 4 pending)
  • In a rust:1 container (Rust 1.100), on a copy of cli/ with the root package.json and product.json:
    • cargo test --locked: passed (235 passed)
    • cargo fmt --check: no differences in changed lines; this rustfmt flags existing code elsewhere
    • cargo clippy --all-targets --locked -- -D warnings: two errors, both in existing tests this change doesn't touch (an unnecessary clone to create a slice in commands/agent_host.rs, and clippy::async_yields_async in tunnels/agent_host.rs), from lints in this newer clippy
  • Not tested end to end with a real Dev Container, since no published CLI has the flag yet.

The Dev Container launcher turned on client forwarding by prefixing the
spawn command with VSCODE_AGENT_HOST_CLIENT_FORWARDING=1. That was
implicit, and since the launcher reuses a running Agent Host of the same
quality, it could pick one started without forwarding, for example by a
remote editor's server.

`code agent host --client-forwarding` now records `clientForwarding` in
the Agent Host's endpoint registry entry and sets the variable for its
server only with the flag, removing it otherwise. The launcher passes
the flag and reuses only Agent Hosts started with it. The client's own
CLI, the latest CLI of dev builds and fallback CLIs from 1.149 on have
the flag; with an older fallback CLI, the Agent Host does not forward.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Registration polling can select a non-forwarding endpoint, and failed CLI refreshes can incorrectly enable an unsupported forwarding flag, causing missing credential forwarding or registration timeouts.

2 open issues
What changed in this PR

Makes Dev Container client forwarding an explicit CLI opt-in, following #350751. The endpoint registry now identifies forwarding-enabled Agent Hosts so the launcher can select compatible instances.

Changes:

  • Adds hidden --client-forwarding support, argument conflict checks, and explicit control of the server’s forwarding environment variable.
  • Records forwarding status and uses it for Dev Container host reuse, with compatibility handling for older fallback CLIs.
  • Updates Rust and TypeScript tests and documents the launch behavior.
File Description
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md Documents forwarding-aware launches and older CLI behavior.
src/​vs/​platform/​agentHost/​test/​node/​sshRemoteAgentHostHelpers.test.ts Tests spawn options and CLI version detection.
src/​vs/​platform/​agentHost/​test/​node/​devContainerAgentHostService.test.ts Tests forwarding-aware host selection and fallback CLIs.
src/​vs/​platform/​agentHost/​test/​node/​agentHostEndpointRegistry.test.ts Tests forwarding metadata parsing.
src/​vs/​platform/​agentHost/​node/​sshRemoteAgentHostHelpers.ts Adds the spawn flag and version-support helper.
src/​vs/​platform/​agentHost/​node/​serviceBootstrapping.md Documents CLI-controlled forwarding startup.
src/​vs/​platform/​agentHost/​node/​remoteAgentHostCliInstaller.ts Returns fallback CLI version information.
src/​vs/​platform/​agentHost/​node/​devContainerAgentHostService.ts Requests forwarding and filters reusable endpoints.
src/​vs/​platform/​agentHost/​node/​agentHostClientForwarding.ts Updates the environment-variable documentation comment.
src/​vs/​platform/​agentHost/​LOCAL_ENDPOINT.md Documents the optional registry field.
src/​vs/​platform/​agentHost/​common/​agentHostEndpointRegistry.ts Validates and preserves forwarding metadata.
cli/​src/​tunnels/​agent_host.rs Controls the server environment and publishes forwarding status.
cli/​src/​tunnels/​agent_host_registry.rs Serializes forwarding status and carries it through selection.
cli/​src/​commands/​args.rs Defines the hidden flag and incompatible modes.
cli/​src/​commands/​agent_relay.rs Updates a registry test fixture.
cli/​src/​commands/​agent_host.rs Propagates the flag and rejects incompatible supervisor reuse.

Review effort: Balanced

The Dev Container launcher again reuses the Agent Host running in the
container however it was started, so the endpoint registry no longer
records client forwarding. Instead, an editor window connected to a Dev
Container asks its server, with the new `clientForwarding` connection
option, to start its Agent Host with forwarding, since the launcher may
reuse that one.

The launcher now stops waiting for a new Agent Host to register as soon
as its start command fails, and starts it again without
`--client-forwarding` when a 1.149 CLI from before the flag rejects it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chrmarti Christof Marti (chrmarti) changed the title agentHost: opt into client forwarding with a CLI flag agentHost: turn on client forwarding with a CLI flag and from editor windows Nov 28, 2026
@chrmarti
Christof Marti (chrmarti) requested a balanced review from Copilot November 28, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Credential, SSH-agent, and GPG forwarding across shared hosts lacks real Dev Container end-to-end validation, requiring maintainer checks of launcher-first startup, editor-first reuse, and crash restarts.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@chrmarti
Christof Marti (chrmarti) marked this pull request as ready for review November 28, 2026 16:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants